﻿using System;
using CardGamesLibrary.Cards;
using CardGamesLibrary.Cards.Piles;
using CardGamesLibrary.Rules;

namespace CardGamesLibrary.Solitaire
{

    public abstract class SolitairePile : CardPile<FrenchDeckCard>
    {
        ICardRule<FrenchDeckCard>[] _rules;

        protected SolitairePile()
        {
            _rules = new ICardRule<FrenchDeckCard>[0];
        }
        protected SolitairePile(params ICardRule<FrenchDeckCard>[] pileRules) : this()
        {
            if (pileRules != null && pileRules.Length > 0)
            {
                _rules = pileRules;
            }
            else 
            { 
                
            }
        }

        public override bool CanAdd(FrenchDeckCard item)
        {
            // to allow a card to be added all the rules must return true
            foreach (var rule in _rules)
            {
                if (rule.CanAddCard(this, item) == false)
                    return false;

            }
            return true;
        }
    }
}
